package lesson14.protobuf;

import com.alibaba.fastjson.JSON;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * <br/>
 * Created on : 2018-02-26 23:15
 * @author lizebin
 */
public class Main {

	public static void main(String[] args) throws InvalidProtocolBufferException {
		School.Student student = School.Student.newBuilder().setAge(18).setAddress("address").setName("name").build();
		byte[] byteArray = student.toByteArray();

		School.Student student1 = School.Student.parseFrom(byteArray);
		System.out.println("hasName() = " + student1.hasName());
		System.out.println("getName() = " + student1.getName());
		System.out.println(student1);

		Sinoxk.Person person = Sinoxk.Person.newBuilder().setAddress("address").build();
		Sinoxk.Message message = Sinoxk.Message.newBuilder().setDataType(Sinoxk.Message.DataType.PersonType).setPerson(person).build();

		System.out.println("hasDataType:" + message.hasDataType());
		System.out.println("is person dataType:" + (message.getDataType() == Sinoxk.Message.DataType.PersonType));
		System.out.println("is Dog dataType:" + (message.getDataType() == Sinoxk.Message.DataType.DogType));
	}

}
